package com.zlm.WebCrawler;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author 13026
 */
public class WenCrawler_demo {
    /*
    * 网络爬虫
    * */
    public static void main(String[] args) throws IOException {
        String net = "https://www.163.com/?from=https://www.163.com/dy/article/J7I8S1BS055669RQ.html";
        webCrawler(net);
    }

    public static void webCrawler(String net) throws IOException {
        StringBuilder sb = new StringBuilder();
        URL url = new URL(net);
        // 链接上这个网址
        URLConnection coon = url.openConnection();
        // 字节流转字符流
        InputStreamReader isr = new InputStreamReader(coon.getInputStream());
        int b;
        while ((b = isr.read()) != -1 ){
            sb.append((char) b);
        }
        isr.close();
        System.out.println(sb.toString());
    }
}
